from math import ceil
from typing import *
from heapq import heappush, heappop


class Solution:

    def maxKelements(self, nums: List[int], k: int) -> int:
        q = []
        for num in nums:
            heappush(q, -num)
        ans = 0
        while k > 0:
            k -= 1
            num = -heappop(q)
            ans += num
            heappush(q, -((num + 2) // 3))

        return ans